/*
 * @Date: 2022-04-06 18:26:15
 * @LastEditors: sailornpg
 * @LastEditTime: 2022-04-21 20:48:26
 * @FilePath: \weibovue\src\hooks\useScroll.ts
 * @Description: 滚动
 */
import { onMounted, ref, onUnmounted } from "vue";
const useScroll = (threshold: number) => {
  const isFlag = ref(false);
  const handler = (e: Event) => {
    const target = document.querySelector("html");
    const top = target!.scrollTop;
    if (top > threshold) {
      isFlag.value = true;
    } else {
      isFlag.value = false;
    }
  };
  onMounted(() => {
    window.addEventListener("scroll", handler);
  });
  onUnmounted(() => {
    window.removeEventListener("scroll", handler);
  });
  return { isFlag };
};
export default useScroll;
